Skip to content

Slider

Sub classes

Name Children Inherits
SpanSlider
prettyqt.custom_widgets.editors.spanslider

    Base classes

    Name Children Inherits
    AbstractSliderMixin
    prettyqt.widgets.abstractslider
    QSlider
    PySide6.QtWidgets
    QSlider(self, orientation: PySide6.QtCore.Qt.Orientation, /, parent: PySide6.QtWidgets.QWidget | None \= None, *, tickPosition: PySide6.QtWidgets.QSlider.TickPosition | None \= None, tickInterval: int | None \= None) -> None

    ⋔ Inheritance diagram

    graph TD
      780639236["widgets.Slider"]
      3920585708["widgets.AbstractSliderMixin"]
      829357528["widgets.WidgetMixin"]
      3227531497["core.ObjectMixin"]
      2751680898["builtins.object"]
      625385617["gui.PaintDeviceMixin"]
      2650392053["QtWidgets.QSlider"]
      229763307["QtWidgets.QAbstractSlider"]
      3620195106["QtWidgets.QWidget"]
      3984060476["QtCore.QObject"]
      37984305["Shiboken.Object"]
      673956333["QtGui.QPaintDevice"]
      3920585708 --> 780639236
      829357528 --> 3920585708
      3227531497 --> 829357528
      2751680898 --> 3227531497
      625385617 --> 829357528
      2751680898 --> 625385617
      2751680898 --> 829357528
      2751680898 --> 3920585708
      2650392053 --> 780639236
      229763307 --> 2650392053
      3620195106 --> 229763307
      3984060476 --> 3620195106
      37984305 --> 3984060476
      2751680898 --> 37984305
      673956333 --> 3620195106
      37984305 --> 673956333

    🛈 DocStrings

    Bases: AbstractSliderMixin, QSlider

    Vertical or horizontal slider.

    Source code in prettyqt/widgets/slider.py
    class Slider(widgets.AbstractSliderMixin, widgets.QSlider):
        """Vertical or horizontal slider."""
    
        value_changed = core.Signal(int)
        clicked = core.Signal(int)
    
        def __init__(self, *args, **kwargs):
            match args:
                case (str(), *rest):
                    super().__init__(constants.ORIENTATION[args[0]], *rest, **kwargs)
                case _:
                    super().__init__(*args, **kwargs)
            self.valueChanged.connect(self.on_value_change)
            # style = HollowHandleStyle(
            #     {
            #         "groove.height": 4,
            #         "sub-page.color": gui.QColor(72, 210, 242),
            #         "add-page.color": gui.QColor(255, 255, 255, 50),
            #         "handle.color": gui.QColor(72, 210, 242),
            #         "handle.ring-width": 2,
            #         "handle.hollow-radius": 10,
            #         "handle.margin": 0,
            #     }
            # )
            # self.setStyle(style)
    
        def mousePressEvent(self, e: gui.QMouseEvent):
            self.clicked.emit(self.value())
            if self.orientation() == constants.Orientation.Horizontal:
                value = e.pos().x() / self.width() * self.maximum()
            else:
                value = (self.height() - e.pos().y()) / self.height() * self.maximum()
    
            self.setValue(int(value))
            super().mousePressEvent(e)
    
        def set_tick_position(
            self, position: TickPositionAllStr | widgets.QSlider.TickPosition
        ):
            """Set the tick position for the slider.
    
            For vertical orientation, "above" equals to "left" and "below" to "right".
    
            Args:
                position: position for the ticks
            """
            if position == "left":
                position = "above"
            elif position == "right":
                position = "below"
            self.setTickPosition(TICK_POSITION.get_enum_value(position))
    
        def get_tick_position(self) -> TickPositionStr:
            """Return tick position.
    
            Returns:
                tick position
            """
            return TICK_POSITION.inverse[self.tickPosition()]
    

    get_tick_position() -> TickPositionStr

    Return tick position.

    Source code in prettyqt/widgets/slider.py
    def get_tick_position(self) -> TickPositionStr:
        """Return tick position.
    
        Returns:
            tick position
        """
        return TICK_POSITION.inverse[self.tickPosition()]
    

    set_tick_position(position: TickPositionAllStr | widgets.QSlider.TickPosition)

    Set the tick position for the slider.

    For vertical orientation, "above" equals to "left" and "below" to "right".

    Parameters:

    Name Type Description Default
    position TickPositionAllStr | TickPosition

    position for the ticks

    required
    Source code in prettyqt/widgets/slider.py
    def set_tick_position(
        self, position: TickPositionAllStr | widgets.QSlider.TickPosition
    ):
        """Set the tick position for the slider.
    
        For vertical orientation, "above" equals to "left" and "below" to "right".
    
        Args:
            position: position for the ticks
        """
        if position == "left":
            position = "above"
        elif position == "right":
            position = "below"
        self.setTickPosition(TICK_POSITION.get_enum_value(position))
    

    :fa-brands-github: Show source on GitHub